package controller.activiti;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.activiti.engine.ActivitiException;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 
 * 常规启动activiti
 * 
 * @author hxl 2018年12月29日
 */
@Controller
public class TestActivitiController {
	/*
	 * @RequestMapping("testActiviti") public void test(){ deploy(); }
	 *//**
		 * 部署流程
		 */
	/*
	 * public void deploy(){ ProcessEngine processEngine =
	 * ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(
	 * "activiti.cfg.xml","processEngineConfiguration").buildProcessEngine();
	 * RepositoryService repositoryService = processEngine.getRepositoryService();
	 * repositoryService.createDeployment()
	 * .addClasspathResource("activitiBMPNXML/VacationRequest.bpmn20.xml")
	 * .deploy(); System.out.println(processEngine.getName()); }
	 *//**
		 * 发起流程
		 */
	/*
	 * public void run(){ ProcessEngine processEngine =
	 * ProcessEngines.getDefaultProcessEngine();
	 * 
	 * 
	 * System.out.println(processEngine.getName());
	 * 
	 * 
	 * Map<String, Object> variables = new HashMap<String, Object>();
	 * variables.put("employeeName", "Kermit"); variables.put("numberOfDays", new
	 * Integer(4)); variables.put("vacationMotivation", "I'm really tired!");
	 * 
	 * RuntimeService runtimeService = processEngine.getRuntimeService();
	 * ProcessInstance processInstance =
	 * runtimeService.startProcessInstanceByKey("vacationRequest", variables);
	 * System.out.println(runtimeService.createProcessInstanceQuery().count()); }
	 * 
	 *//**
		 * 完成任务
		 */
	/*
	 * public void task(){ ProcessEngine processEngine =
	 * ProcessEngines.getDefaultProcessEngine(); TaskService taskService =
	 * processEngine.getTaskService(); List<Task> tasks =
	 * taskService.createTaskQuery().taskCandidateGroup("management").list(); for
	 * (Task task : tasks) { System.out.println(task.getId());
	 * System.out.println(task.getName()); Map<String, Object> taskVariables = new
	 * HashMap<String, Object>(); taskVariables.put("vacationApproved", "false");
	 * taskVariables.put("managerMotivation", "We have a tight deadline!");
	 * taskService.complete(task.getId(), taskVariables); } }
	 * 
	 *//**
		 * 挂起和激活
		 *//*
			 * public void HangAndActivation(){
			 * 
			 * //相关的表 act_re_procdef SUSPENSION_STATE_ 1 激活 2 挂起 ProcessEngine processEngine
			 * = ProcessEngines.getDefaultProcessEngine(); RepositoryService
			 * repositoryService = processEngine.getRepositoryService(); RuntimeService
			 * runtimeService = processEngine.getRuntimeService();
			 * repositoryService.suspendProcessDefinitionByKey("vacationRequest"); try {
			 * repositoryService.activateProcessDefinitionByKey("vacationRequest");
			 * runtimeService.startProcessInstanceByKey("vacationRequest"); } catch
			 * (ActivitiException e) { e.printStackTrace(); } }
			 */
}
